﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using VNPT.Excel;
using VNPT.Data;

namespace VNPT.DoiSoat.DoiSoat
{
    public partial class u115_VTT_6_DNK_GTGT_DLK : VNPT.Core.uBase
    {
        public u115_VTT_6_DNK_GTGT_DLK()
        {
            InitializeComponent();

        }
        public override void SaveSetting()
        {

            base.SaveSetting();
        }

        public override void LoadSetting()
        {
            mySQLEditor1.Text = DoiSoatSetting.SQL_VTT6_GTGT_108_801;
            mySQLEditor2.Text = DoiSoatSetting.SQL_VTT6_GTGT_106;
            base.LoadSetting();
        }

       
        

        private void btnRun_Click(object sender, EventArgs e)
        {
            if (xtraTabControl1.SelectedTabPage == xtraTabPage1)//108 801
            {
                var sql = string.Format(mySQLEditor1.Text, DoiSoatSetting.NAM, DoiSoatSetting.THANG);
                var kq = DbServer.GetDataTable(new QueryCommandConfig(sql));
                myGridControl3.DataSource = ChuyenDoi(kq);
            }
            else
            {
                var sql = string.Format(mySQLEditor2.Text, DoiSoatSetting.NAM, DoiSoatSetting.THANG);
                var kq=DbServer.GetDataTable(new QueryCommandConfig(sql));
                myGridControl3.DataSource = ChuyenDoi(kq);
            }
        }

        private List<Data.VTT_6_GTGT> ChuyenDoi(DataTable dt)
        {
            List<Data.VTT_6_GTGT> li = new List<Data.VTT_6_GTGT>();
            foreach (var item in dt.Rows)
            {
                var dr = ((DataRow)item);
                double i = 0;
                var dv = (dr["DV"] ?? "").ToString();

                double.TryParse((dr["block_60s"] ?? "0").ToString(), out i);
                var block6 = i;
                i = 0;
                double.TryParse((dr["block_1s"] ?? "0").ToString(), out i);
                var block1 = i;
                li.Add(new VTT_6_GTGT()
                {
                     Block1_DLK =block1, Block6_DLK =block6, DichVu = dv
                });
            }
            return li;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            if (xtraTabControl1.SelectedTabPage == xtraTabPage1)//108 801
            {
                DoiSoatSetting.SQL_VTT6_GTGT_108_801 = mySQLEditor1.Text;
            }
            else
            {
                DoiSoatSetting.SQL_VTT6_GTGT_106= mySQLEditor2.Text;
            }
        }

        private void btnXuat_Click(object sender, EventArgs e)
        {
            new VNPT.Utility.Grid.GridExport().Export(myGridControl3);
        }
    }
}
